package wordroid.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.StringTokenizer;
import wordroid.model.BookList;
import wordroid.model.Word;
import wordroid.model.WordList;

public class DataAccess
{
  public static int NumOfAttention;
  public static String bookID = "";
  public static boolean ifContinue;
  public static String listID;
  public Context context;
  private SqlHelper helper = new SqlHelper();

  public DataAccess(Context paramContext)
  {
    Cursor localCursor = this.helper.Query(paramContext, SqlHelper.ATTENTION_TABLE, null, null, null, null, null, null);
    if (localCursor == null)
      NumOfAttention = 0;
    while (true)
    {
      localCursor.close();
      this.context = paramContext;
      return;
//      if (localCursor.getCount() == 0)
//        NumOfAttention = 0;
//      if (!(localCursor.moveToLast()))
//        continue;
//      NumOfAttention = Integer.parseInt(localCursor.getString(0));
    }
  }

  public void DeleteBook()
  {
    this.helper.Delete(this.context, SqlHelper.WORDLIST_TABLE, "BOOKID ='" + bookID + "'", null);
    this.helper.Delete(this.context, SqlHelper.BOOKLIST_TABLE, "ID ='" + bookID + "'", null);
    this.helper.DeleteTable(this.context, bookID);
  }

  public void DeleteFromAttention(Word paramWord)
  {
    this.helper.Delete(this.context, SqlHelper.ATTENTION_TABLE, "ID ='" + paramWord.getID() + "'", null);
  }

  public void InsertIntoAttention(Word paramWord)
  {
    ContentValues localContentValues = new ContentValues();
    localContentValues.put("ID", String.valueOf(1 + NumOfAttention));
    localContentValues.put("SPELLING", paramWord.getSpelling());
    localContentValues.put("MEANNING", paramWord.getMeanning());
    localContentValues.put("PHONETIC_ALPHABET", paramWord.getPhonetic_alphabet());
    localContentValues.put("LIST", "Attention");
    this.helper.Insert(this.context, SqlHelper.ATTENTION_TABLE, localContentValues);
  }

  public void InsertIntoList(WordList paramWordList)
  {
    ContentValues localContentValues = new ContentValues();
    localContentValues.put("BOOKID", paramWordList.getBookID());
    localContentValues.put("LIST", paramWordList.getList());
    localContentValues.put("LEARNED", paramWordList.getLearned());
    localContentValues.put("LEARN_TIME", paramWordList.getLearnedTime());
    localContentValues.put("REVIEW_TIMES", paramWordList.getReview_times());
    localContentValues.put("REVIEWTIME", paramWordList.getReviewTime());
    localContentValues.put("BESTSCORE", paramWordList.getBestScore());
    localContentValues.put("SHOULDREVIEW", paramWordList.getShouldReview());
    this.helper.Insert(this.context, SqlHelper.WORDLIST_TABLE, localContentValues);
  }

  public ArrayList<Word> QueryAttention(String paramString, String[] paramArrayOfString)
  {
    Cursor localCursor = this.helper.Query(this.context, SqlHelper.ATTENTION_TABLE, null, paramString, paramArrayOfString, null, null, null);
    ArrayList localArrayList = new ArrayList();
    if (localCursor.moveToFirst())
      do
      {
        Word localWord = new Word();
        localWord.setID(localCursor.getString(0));
        localWord.setSpelling(localCursor.getString(1));
        localWord.setMeanning(localCursor.getString(2));
        localWord.setPhonetic_alphabet(localCursor.getString(3));
        localWord.setList(localCursor.getString(4));
        localArrayList.add(localWord);
      }
      while (localCursor.moveToNext());
    localCursor.close();
    return localArrayList;
  }

  public ArrayList<BookList> QueryBook(String paramString, String[] paramArrayOfString)
  {
    Cursor localCursor = this.helper.Query(this.context, SqlHelper.BOOKLIST_TABLE, null, paramString, paramArrayOfString, null, null, null);
    ArrayList localArrayList = new ArrayList();
    if (localCursor.moveToFirst())
      do
      {
        BookList localBookList = new BookList();
        localBookList.setID(localCursor.getString(0));
        localBookList.setName(localCursor.getString(1));
        localBookList.setGenerateTime(localCursor.getString(2));
        localBookList.setNumOfList(localCursor.getString(3));
        localBookList.setNumOfWord(localCursor.getInt(4));
        localArrayList.add(localBookList);
      }
      while (localCursor.moveToNext());
    localCursor.close();
    return localArrayList;
  }

  public ArrayList<WordList> QueryList(String paramString, String[] paramArrayOfString)
  {
    Cursor localCursor = this.helper.Query(this.context, SqlHelper.WORDLIST_TABLE, null, paramString, paramArrayOfString, null, null, null);
    ArrayList localArrayList = new ArrayList();
    if (localCursor.moveToFirst())
      do
      {
        WordList localWordList = new WordList();
        localWordList.setBookID(localCursor.getString(0));
        localWordList.setList(localCursor.getString(1));
        localWordList.setLearned(localCursor.getString(2));
        localWordList.setLearnedTime(localCursor.getString(3));
        localWordList.setReview_times(localCursor.getString(4));
        localWordList.setReviewTime(localCursor.getString(5));
        localWordList.setBestScore(localCursor.getString(6));
        localWordList.setShouldReview(localCursor.getString(7));
        localArrayList.add(localWordList);
      }
      while (localCursor.moveToNext());
    localCursor.close();
    return localArrayList;
  }

  public ArrayList<Word> QueryWord(String paramString, String[] paramArrayOfString)
  {
    Cursor localCursor = this.helper.Query(this.context, bookID, null, paramString, paramArrayOfString, null, null, null);
    ArrayList localArrayList = new ArrayList();
    if (localCursor.moveToFirst())
      do
      {
        Word localWord = new Word();
        localWord.setID(localCursor.getString(0));
        localWord.setSpelling(localCursor.getString(1));
        localWord.setMeanning(localCursor.getString(2));
        localWord.setPhonetic_alphabet(localCursor.getString(3));
        localWord.setList(localCursor.getString(4));
        localArrayList.add(localWord);
      }
      while (localCursor.moveToNext());
    localCursor.close();
    return localArrayList;
  }

  public void ResetBook()
  {
    new ArrayList();
    ArrayList localArrayList = QueryList("BOOKID ='" + bookID + "'", null);
    for (int i = 0; ; ++i)
    {
      if (i >= localArrayList.size())
        return;
      WordList localWordList = (WordList)localArrayList.get(i);
      localWordList.setBestScore("");
      localWordList.setLearned("0");
      localWordList.setLearnedTime("");
      localWordList.setReview_times("0");
      localWordList.setReviewTime("");
      localWordList.setShouldReview("0");
      UpdateList(localWordList);
    }
  }

  public void UpdateAttention(Word paramWord)
  {
    ContentValues localContentValues = new ContentValues();
    localContentValues.put("ID", paramWord.getID());
    localContentValues.put("SPELLING", paramWord.getSpelling());
    localContentValues.put("MEANNING", paramWord.getMeanning());
    localContentValues.put("PHONETIC_ALPHABET", paramWord.getPhonetic_alphabet());
    localContentValues.put("LIST", paramWord.getList());
    this.helper.Update(this.context, SqlHelper.ATTENTION_TABLE, localContentValues, "ID ='" + paramWord.getID() + "'", null);
  }

  public void UpdateList(WordList paramWordList)
  {
    ContentValues localContentValues = new ContentValues();
    localContentValues.put("BOOKID", paramWordList.getBookID());
    localContentValues.put("LIST", paramWordList.getList());
    localContentValues.put("LEARNED", paramWordList.getLearned());
    localContentValues.put("LEARN_TIME", paramWordList.getLearnedTime());
    localContentValues.put("REVIEW_TIMES", paramWordList.getReview_times());
    localContentValues.put("REVIEWTIME", paramWordList.getReviewTime());
    localContentValues.put("BESTSCORE", paramWordList.getBestScore());
    localContentValues.put("SHOULDREVIEW", paramWordList.getShouldReview());
    this.helper.Update(this.context, SqlHelper.WORDLIST_TABLE, localContentValues, " BOOKID ='" + paramWordList.getBookID() + "'AND LIST ='" + paramWordList.getList() + "'", null);
  }

  public boolean initBook(String paramString1, ArrayList<Word> paramArrayList, String paramString2, String paramString3)
    throws Exception
  {
    Cursor localCursor = this.helper.Query(this.context, SqlHelper.BOOKLIST_TABLE, null, null, null, null, null, null);
    String str1 = "book1";
    if (localCursor.moveToLast())
    {
      StringTokenizer localStringTokenizer = new StringTokenizer(localCursor.getString(0), "book");
      str1 = "book" + (1 + Integer.parseInt(localStringTokenizer.nextToken()));
    }
    wordroid.activitys.ImportBook.result = str1;
    localCursor.close();
    Calendar localCalendar = Calendar.getInstance();
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String str2 = localSimpleDateFormat.format(localCalendar.getTime());
    ContentValues localContentValues = new ContentValues();
    this.helper.CreateTable(this.context, str1);
    int i = 0;
    int j = paramArrayList.size();
    WordList localWordList;
    int k;
    if (i >= j)
    {
      localWordList = new WordList();
      new SimpleDateFormat("yyyy-MM-dd");
      k = 0;
//      label185: int l = Integer.parseInt(paramString2);
//      if (k < l)
//        break label440;
      bookID = str1;
      localContentValues.clear();
      localContentValues.put("ID", str1);
      localContentValues.put("NAME", paramString3);
      localContentValues.put("GENERATE_TIME", str2);
      localContentValues.put("NUMOFLIST", paramString2);
      localContentValues.put("NUMOFWORD", Integer.valueOf(paramArrayList.size()));
      this.helper.Insert(this.context, SqlHelper.BOOKLIST_TABLE, localContentValues);
      Log.i("select", bookID);
    }
    for (int i1 = 1; ; i1 = 0)
    {
      while (true)
      {
     //   return i1;
        if (ifContinue)
        {
          localContentValues.put("ID", ((Word)paramArrayList.get(i)).getID());
          localContentValues.put("SPELLING", ((Word)paramArrayList.get(i)).getSpelling());
          localContentValues.put("MEANNING", ((Word)paramArrayList.get(i)).getMeanning());
          localContentValues.put("PHONETIC_ALPHABET", ((Word)paramArrayList.get(i)).getPhonetic_alphabet());
          localContentValues.put("LIST", ((Word)paramArrayList.get(i)).getList());
          this.helper.Insert(this.context, str1, localContentValues);
          Log.i("Inserting word:", ((Word)paramArrayList.get(i)).getSpelling());
          ++i;
        }
        i1 = 0;
      }
//      label440: if (!(ifContinue))
//        continue;
//      localWordList.setBestScore("");
//      localWordList.setBookID(str1);
//      localWordList.setLearned("0");
//      localWordList.setLearnedTime("");
//      localWordList.setList(String.valueOf(k + 1));
//      localWordList.setReview_times("0");
//      localWordList.setReviewTime("");
//      localWordList.setShouldReview("0");
//      InsertIntoList(localWordList);
//      ++k;
    //  break label185:
    }
  }
}

/* Location:           E:\Desktop\Android\英语词汇记忆\classes_dex2jar.jar
 * Qualified Name:     wordroid.database.DataAccess
 * JD-Core Version:    0.5.3
 */